home *** CD-ROM | disk | FTP | other *** search
/ IRIX 6.5 Complementary Applications 2004 February / SGI IRIX 6.5 Complementary Applications 2004 February.iso / dist / OpenOffice.idb / usr / OpenOffice / help / en / sbasic.jar / text / sbasic / common / 03020404.xml < prev    next >
Encoding:
Extensible Markup Language  |  2002-01-24  |  4.7 KB  |  64 lines

  1. <?xml version="1.0" encoding="utf-8"?>
  2. <html><head><title>Dir Function [Runtime]</title><meta name="filename" content="text/sbasic/common/03020404"/><meta name="language" content="en-US"/><help:css-file-link xmlns:help="http://openoffice.org/2000/help"/><!--The CSS style header method for setting styles--><style type="text/css">
  3.  
  4.         p.P1{
  5.                 }
  6.         p.P2{
  7.                 }
  8.         span.T1{
  9.                 font-weight:bold;}
  10.         </style></head><body>
  11.   
  12.   
  13.   <help:to-be-embedded Eid="dir" xmlns:help="http://openoffice.org/2000/help">
  14.   <p class="Head1"><help:link Id="66557">Dir Function [Runtime]</help:link></p>
  15.   <p class="Paragraph">Returns the name of a file, directory, or all files and folders of a drive or directory that match the specified search path.</p>
  16.   </help:to-be-embedded>
  17.   <p class="Paragraph"><span class="T1">Syntax</span>:</p>
  18.   <p class="Paragraph">Dir [(Text As String) [, Attrib As Integer]] <help:key-word value="Dir" tag="kw66557_1" xmlns:help="http://openoffice.org/2000/help"/></p>
  19.   <p class="Paragraph"><span class="T1">Return value</span>:</p>
  20.   <p class="Paragraph">String</p>
  21.   <p class="Paragraph"><span class="T1">Parameter</span>:</p>
  22.   <p class="Paragraph">Text: Any string expression that specifies the search path, directory or file. This argument must only be specified the first time you call the Dir function. The <help:link Id="66636" Eid="urllocal" xmlns:help="http://openoffice.org/2000/help">URL notation</help:link> can also be used here.</p>
  23.   <p class="Paragraph">Attrib: Any integer expression which specifies bitwise file attributes. The Dir function returns only files or directories that match the specified attributes. Various attributes can be combined by adding the attribute values:</p>
  24.   <p class="P2">attrib:</p>
  25.   <p class="Paragraph">0 : Normal files.</p>
  26.   <p class="Paragraph">2 : Hidden files.</p>
  27.   <p class="Paragraph">4 : System files.</p>
  28.   <p class="Paragraph">8 : Returns the name of the volume</p>
  29.   <p class="Paragraph">16 : Returns the name of the directory only.</p>
  30.   <p class="Paragraph">You can use this function either to check whether a file or directory exists, or to determine all files and folders in a specific directory.</p>
  31.   <p class="Paragraph">To check whether a file exists, enter the complete path name along with the file name. If the Dir function returns a name, the directory or file exists. When no file or directory names match, Dir Function returns a zero-length string ("").</p>
  32.   <p class="Paragraph">To generate a list of all existing files in a specific directory, proceed as follows: The first time you call the Dir function specify the complete search path of the files, e.g., "D:\OFFICE4\*.SDW". If the path is correct and the search resulted in at least one file, the function returns the name of the first file that matches the search path. To return any additional file names that match pathname, call Dir again with no arguments. If the Dir function returns a zero-length string (""), this means that no more file names exist that match the search criteria.</p>
  33.   <p class="Paragraph">To return directories only, use the attribute parameter. The same applies if you want to determine the name of a volume (e.g., a hard drive partition)</p>
  34.   <p class="P2">Example:</p>
  35.   <p class="PropText">Sub ExampleDir</p>
  36.   <p class="PropText">REM Displays all files and directories</p>
  37.   <p class="PropText">Dim sFile as String, sPath As String</p>
  38.   <p class="PropText">Dim sDir as String, sValue as String</p>
  39.   <p class="PropText">Dim iFIle as Integer</p>
  40.   <p class="PropText">sFile= "Files: "</p>
  41.   <p class="PropText">sDir="Directories:"</p>
  42.   <p class="PropText">iFile = 0</p>
  43.   <p class="PropText">sPath = CurDir</p>
  44.   <p class="PropText">sValue = Dir$(sPath,22) <text:s text:c="2" xmlns:text="http://openoffice.org/2000/text"/>REM 16 + 2 + 4</p>
  45.   <p class="PropText">Do</p>
  46.   <p class="PropText">If sValue <> "." and sValue <> ".." Then</p>
  47.   <p class="PropText">if (GetAttr( sPath + getPathSeparator + sValue) AND 16) >0 then</p>
  48.   <p class="PropText">REM here the directories</p>
  49.   <p class="PropText">sDir = sDir & chr(13) & sValue</p>
  50.   <p class="PropText">else</p>
  51.   <p class="PropText">REM here the files</p>
  52.   <p class="PropText"/>
  53.   <p class="PropText">if iFile Mod 3 = 0 then sFile = sFile + Chr(13)</p>
  54.   <p class="PropText">iFile = iFile + 1</p>
  55.   <p class="PropText">sFile = sFile + sValue &"; "</p>
  56.   <p class="PropText">End If</p>
  57.   <p class="PropText">End If</p>
  58.   <p class="PropText">sValue = Dir$</p>
  59.   <p class="PropText">Loop Until sValue = ""</p>
  60.   <p class="PropText">MsgBox sDir,0,sPath</p>
  61.   <p class="PropText">MsgBox "" & iFile & " " & sFile,0,sPath</p>
  62.   <p class="PropText">End sub</p>
  63.   <p class="PropText"/>
  64.  </body></html>